package com.hg.thread;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @Author: skh
 * @Date: 2019/12/20 11:06
 * @Description:
 */
public class Ticket {

    private AtomicInteger num = new AtomicInteger(30);

    //卖票
    public synchronized void saleTicket() {
        if (num.get() > 0) {
            System.out.println(Thread.currentThread().getName() + "卖出票:" + num.getAndDecrement() + ",剩余票:" + num.get());
        }
    }

    public  void addTicket() {
        int andIncrement = num.getAndIncrement();
        System.out.println(Thread.currentThread().getName() + "加票:" + andIncrement);
    }

}